package com.tanhua.model.vo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@NoArgsConstructor
public class PageResult<T> implements Serializable {

    /**
     * 总记录数
     */
    private Long counts;

    /**
     * 页大小
     */
    private Long pagesize;

    /**
     * 总页数
     */
    private Long pages;

    /**
     * 当前页码
     */
    private Long page;

    /**
     * 列表
     */
    private List<T> items;


    public PageResult(IPage t) {

        this.page = t.getCurrent();
        this.pagesize = t.getSize();
        this.items = t.getRecords();
        this.counts = t.getTotal();
        this.pages = t.getPages();

    }

    public PageResult(Long page, Long pagesize, Long counts, List list) {

        this.page = page;
        this.pagesize = pagesize;
        this.items = list;
        this.counts = counts;
        this.pages = counts % pagesize == 0 ? counts / pagesize : counts / pagesize + 1;
    }

    public PageResult(Integer page, Integer pagesize, Long counts, List list) {

        this.page = Long.valueOf(page);
        this.pagesize = Long.valueOf(pagesize);
        this.items = list;
        this.counts = Long.valueOf(counts);
        this.pages = counts % pagesize == 0 ? counts / pagesize : counts / pagesize + 1;
    }

}